//DONE chiKwadrat change
//DONE kolmogorow + -
//TODO: chiKwadrat trojek
//DONE sprawdz kolejnosc pod testy Tura (chiKwadrat, K-, K+, chiKwadratTrojek)

#include <iostream>
#include <gmpxx.h>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <cstdlib>
#include <algorithm>

using namespace std;

string mpq_to_decimal(mpq_class value, int precision)
{
    if (value == 0)
    {
        return "0";
    }

    string decimal;
    mpz_class numerator = value.get_num();
    mpz_class denominator = value.get_den();

    mpz_class total_part = numerator / denominator;
    decimal += total_part.get_str();
    mpz_class rest = abs(numerator % denominator);

    if (rest != 0)
    {
        decimal += '.';

        int count = 0;
        rest *= 10;
        bool addZero = true;
        while (count < precision)
        {
            mpz_class tmp = rest / denominator;
            if (tmp == 0 && rest % denominator != 0)
            {
                rest *= 10;
                if (addZero)
                {
                    decimal += '0';
                    count++;
                }
                addZero = true;
            }
            else
            {
                decimal += tmp.get_str();
                rest -= tmp * denominator;
                addZero = false;
                count++;
            }
        }
    }

    int shift = 0;
    for (string::reverse_iterator rit = decimal.rbegin(); rit != decimal.rend(); ++rit)
    {
        if (*rit != '0')
        {
            if (*rit == '.')
            {
                shift++;
            }
            break;
        }

        shift++;
    }

    decimal = decimal.substr(0, decimal.size() - shift);

    return decimal;
}

void prepareTestChi(mpq_class intervals[], mpq_class probabilities_chi[], int k_chi)
{
    mpz_class integerNumber;

    for (int i = 0; i < k_chi; i++)
    {
        integerNumber = pow(i+1, 2);

        mpq_set_num(intervals[i].get_mpq_t(), integerNumber.get_mpz_t());
        integerNumber = 100;

        mpq_set_den(intervals[i].get_mpq_t(), integerNumber.get_mpz_t());
        if (i == 0) {
            integerNumber = 1;
        } else {
            integerNumber = intervals[i].get_num() - intervals[i-1].get_num();
        }

        mpq_set_num(probabilities_chi[i].get_mpq_t(), integerNumber.get_mpz_t());
        integerNumber = 100;

        mpq_set_den(probabilities_chi[i].get_mpq_t(), integerNumber.get_mpz_t());
    }
}

// V = sum(i=1 to k) po [ ( (Y_i - n*p_i)^2 ) / (n*p_i) ]
void computeChiKwadrat(mpz_class Y[], mpq_class probabilities[], unsigned long int count, int k_chi, int precision)
{
    mpq_class rationalNumber;
    mpq_class n = count;
    mpq_class numerator;
    mpq_class helper;
    mpq_class chi;

    for (int i = 0; i < k_chi; i++)
    {
        helper = n * probabilities[i];
        numerator = Y[i] - helper;
        numerator = numerator * numerator;
        chi += numerator / helper;
    }

    cout << mpq_to_decimal(chi, precision) << endl;
}

//  K- = max(1 <= j <= n) z F(Xj) - (j-1)/n, gdzie F(Xj) = Xj
//  K+ = max(1 <= j <= n) z j/n - F(Xj), gdzie F(Xj) = Xj
void computeKolmogorow(vector<mpq_class> numbersFromInput, unsigned long int count, int precision)
{
	mpq_class rationalNumber;
	mpq_class maxKolmogorowPlus;
	mpq_class maxKolmogorowMinus;
	mpq_class j = 0, n = count, X;

    //sort desc
	sort(numbersFromInput.rbegin(), numbersFromInput.rend());

	//init of maxs
	X = numbersFromInput.back();
	//K-
	maxKolmogorowMinus = j / n;
	maxKolmogorowMinus = X - maxKolmogorowMinus;
	//K+
	j++;
	maxKolmogorowPlus = j / n;
	maxKolmogorowPlus -= X;
	numbersFromInput.pop_back();

	while (!numbersFromInput.empty())
	{
		X = numbersFromInput.back();
		//K-
		rationalNumber = j / n;
		rationalNumber = X - rationalNumber;
		if (mpq_cmp(rationalNumber.get_mpq_t(), maxKolmogorowMinus.get_mpq_t()) > 0) {
            maxKolmogorowMinus = rationalNumber;
		}
		//K+
		j++;
		rationalNumber = j / n;
		rationalNumber -= X;
		if (mpq_cmp(rationalNumber.get_mpq_t(), maxKolmogorowPlus.get_mpq_t()) > 0) {
			maxKolmogorowPlus = rationalNumber;
        }
		numbersFromInput.pop_back();
	}

    cout << mpq_to_decimal(maxKolmogorowMinus, precision) << endl;
    cout << mpq_to_decimal(maxKolmogorowPlus, precision) << endl;
}

int getTripleCoordinate(mpq_class value)
{
  mpq_class boundOne(1, 3);
  mpq_class boundTwo(2, 3);
  
  if (mpq_cmp(value.get_mpq_t(), boundOne.get_mpq_t()) < 0)
  {
    return 0;
  }
  else if (mpq_cmp(value.get_mpq_t(), boundTwo.get_mpq_t()) < 0)
  {
    return 1;
  }
  else
  {
    return 2;
  }
}

void calculateChiTriples(vector<mpq_class> &inputs, int precision, int count)
{
  int size = 3;
  int Yi[size][size][size];
  
  for (int i = 0; i < size; i++)
  {
    for (int j = 0; j < size; j++)
    {
      for (int k = 0; k < size; k++)
      {
	Yi[i][j][k] = 0;
      }
    }
  }
  
  mpq_class p(1, 27), sum = 0;
  mpq_class np = count * p;
  int rangesCount = (count / 3) * 3;
  int firstCoordinate, secondCoordinate, thirdCoordinate;
  
  for(int i = 0; i < rangesCount; i += 3)
  {
     firstCoordinate = getTripleCoordinate(inputs[i]);
     secondCoordinate = getTripleCoordinate(inputs[i+1]);
     thirdCoordinate = getTripleCoordinate(inputs[i+2]);
     
     Yi[firstCoordinate][secondCoordinate][thirdCoordinate]++;
  }
  
  for (int i = 0; i < size; i++)
  {
    for (int j = 0; j < size; j++)
    {
      for (int k = 0; k < size; k++)
      {
	mpq_class element = Yi[i][j][k] - np;
	element *= element;
	element /= np;
	sum += element;
      }
    }
  }
  
  cout << mpq_to_decimal(sum, precision) << endl;
}





int main(int argc, char* argv[])
{
    int precision = atoi(argv[1]);

    mpq_class numberFromInput;
    unsigned long int count = 0;
    vector<mpq_class> numbersFromInput;

    /* chi-kwadrat variables and prepare intervals and probabilities */
    const int k_chi = 10;
    mpq_class intervals[k_chi];
    mpq_class probabilities_chi[k_chi];
    mpz_class Y_chi[k_chi];
    prepareTestChi(intervals, probabilities_chi, k_chi);

    ios_base::sync_with_stdio(false);
    while (cin >> numberFromInput)
    {
        mpq_canonicalize(numberFromInput.get_mpq_t());
        numbersFromInput.push_back(numberFromInput);
        count++;

        /* TEST: chi-kwadrat */
        for (int i = 0; i < k_chi; i++)
        {
            if (mpq_cmp(numberFromInput.get_mpq_t(), intervals[i].get_mpq_t()) < 0)
            {
                Y_chi[i]++;
                break;
            }
        }
    }

    computeChiKwadrat(Y_chi, probabilities_chi, count, k_chi, precision);
    computeKolmogorow(numbersFromInput, count, precision);
    calculateChiTriples(numbersFromInput, precision, count);

    return 0;
}
